/*
*类描述：banner新增类
*开发者：sjc
*创建时间：2018-8-19 14:42:36
*/
var bnId;
$(function () {
    $("#case").upload(
        function(_this,data){
            var imgNameStr= data.substring(0,data.lastIndexOf("."));
            var is = $("#imgDesDiv").children(".panel-body");
            $.each(is,function(i,item){
                $(item).hide();
            });


            $("#imgDes_"+imgNameStr).show();
        }
    )
});


//操作中的按钮样式
function addBannerName () {
    var bannerName = $("#bannerName").val();
    if(null==bannerName || bannerName == ""){
        $("#bannerName").addClass("has-error");
    }
    var bannerId = $("#bannerId").val();
    var bnUrl = "/banner/addBanner";
    var paramData1 = {};
    if(null != bannerId && bannerId != "" && bannerId != "undefined"){
        bnUrl="/banner/updateBannerName";
        paramData1 = {"bnId":bannerId,"bannerName":bannerName}
    }else{
        paramData1 = {"bannerName":bannerName};
    }
    var bannerType = $('#bannerType option:selected') .val();
    var paramData2={"bannerType":bannerType};
    var paramData = $.extend(paramData1, paramData2);

    $.ajax({
        url:application.contextPath+bnUrl,
        type:"POST",
        dataType:"json",
        data:paramData,
        success:function (res) {
            if(!res.isSuccess){
                alert("新增Banner名称失败"+data.message);
                return ;
            }else{
                var ret = res.data;
                bnId = ret.bnId;
                $("#bannerId").val(bnId);
                $("#bannerName").hide();
                $("#labBannerName").html(bannerName);
                $("#labBannerName").show();
                $("#saveNameBtn").hide();
                $("#editNameBtn").show();
                $("#bannerType").attr("disabled","disabled");
            }
        }
    });
};

/**
 * 方法描述:编辑banner图片信息
 * SJC 2018-8-29 17:17:44
 *
*/
function editImgDes(item){
    var des = $(item).parent();
    var imgName = des.find("#imgName").html();
    var bnImgDes = des.find("#bnImgDes").val();
    var targetUrl = des.find("#targetUrl").val();
    var bannerItemId =des.find("#bannerItemId").val();
   // alert("imgName:"+imgName+";bnImgDes:"+bnImgDes+";targetUrl:"+targetUrl+";bannerItemId:"+bannerItemId);
    $.ajax({
        url:application.contextPath+"/banner/updateBannerItem",
        type:"POST",
        dataType:"json",
        data:{
            "bannerItemId":bannerItemId,
            "bnImgDes":bnImgDes,
            "targetUrl":targetUrl
        },
        success:function (res) {
            if(!res.isSuccess){
                alert("banner图片编辑失败"+data.message);
                return ;
            }else{
               alert("banner内容保存成功！");
                des.hide();
            }
        }
    });

}

/**
 * 方法描述:保存图片顺序
 * SJC 2018-8-30 16:40:30
 *
*/
function saveImgSn(){
    var imgNames = $("[name='upload']").val();
    $.ajax({
        url:application.contextPath+"/banner/updateBannerItemSn",
        type:"POST",
        dataType:"json",
        data:{
            "itemName":imgNames
        },
        success:function (res) {
            if(!res.isSuccess){
                alert("banner图片编辑失败"+data.message);
                return ;
            }else{
                alert("图片顺序保存成功！");
                // des.hide();
            }
        }
    });

}

/**
 * 方法描述:修改banner名称
 * SJC 2018-8-30 16:41:52
 *
*/
function updateBannerName(){
    $("#bannerName").show();
    $("#labBannerName").hide();
    $("#saveNameBtn").show();
    $("#editNameBtn").hide();
    $("#bannerType").attr("disabled",false);
}

